{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "33c1b088",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import datedelta "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b8c9c84c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_order = pd.read_csv(r\"C:\\Users\\zhengyang\\learning\\Python\\src\\data\\meal_order_info.csv\",\n",
    "                       sep = ',',encoding = 'utf-8')\n",
    "sr_locktime=df_order['lock_time'][:1000:200]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "450dc47f",
   "metadata": {},
   "source": [
    "## 1. 转化为Timestamp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c984c802",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原本 2016/8/1 11:11:46\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Timestamp('2016-08-01 11:11:46')"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print('原本',sr_locktime[0])\n",
    "sr_locktime = pd.to_datetime(sr_locktime)\n",
    "sr_locktime[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9cb1cee",
   "metadata": {},
   "source": [
    "### 1.1 属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "32b9bd8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "a = sr_locktime[0]\n",
    "print(a.year)\n",
    "print(a.month)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2ede8da",
   "metadata": {},
   "source": [
    "## 2. datedelta模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "93ac2aa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "p = datedelta.datedelta(months=1)\n",
    "ts1 = pd.to_datetime(\"2020-11-18 20:33:25\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "820b8b2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2020-12-18 20:33:25')"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts1+p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "cbbf7c5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2020-11-19 20:33:25')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = pd.Timedelta(days=1)\n",
    "ts1+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6dbf19df",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mining",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
